﻿using SqlSugar;
using System;

namespace MyAuthCore.Entity
{
    public class SqlSugarHelper
    {
        public static string ConnectionString = string.Empty;
        public static string DBType { get; set; }
        public static SqlSugarClient CodeFirst
        {
            get
            {
                DbType dbType = DbType.Sqlite;
                switch (DBType.ToLower())
                {
                    case "sqlite":
                        dbType = DbType.Sqlite;
                        break;
                    case "mysql":
                        dbType = DbType.MySql;
                        break;
                    case "postgresql":
                        dbType = DbType.PostgreSQL;
                        break;
                }
                return new SqlSugarClient(new ConnectionConfig()
                {
                    ConnectionString = ConnectionString,//必填, 数据库连接字符串
                    DbType = dbType,         //必填, 数据库类型
                    IsAutoCloseConnection = true,       //默认false, 时候知道关闭数据库连接, 设置为true无需使用using或者Close操作
                    InitKeyType = InitKeyType.Attribute    //默认SystemTable, 字段信息读取, 如：该属性是不是主键，是不是标识列等等信息
                });
            }
        }
        public static SqlSugarClient DB
        {
            get
            {
                DbType dbType = DbType.Sqlite;
                switch (DBType.ToLower())
                {
                    case "sqlite":
                        dbType = DbType.Sqlite;
                        break;
                    case "mysql":
                        dbType = DbType.MySql;
                        break;
                    case "postgresql":
                        dbType = DbType.PostgreSQL;
                        break;
                }
                return new SqlSugarClient(new ConnectionConfig()
                {
                    ConnectionString = ConnectionString,//必填, 数据库连接字符串
                    DbType = dbType,         //必填, 数据库类型
                    IsAutoCloseConnection = true,       //默认false, 时候知道关闭数据库连接, 设置为true无需使用using或者Close操作
                    InitKeyType = InitKeyType.SystemTable    //默认SystemTable, 字段信息读取, 如：该属性是不是主键，是不是标识列等等信息
                });
            }
        }
    }
}
